package com.huluobo.a2208parkdemo.sign

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson
import com.huluobo.a2208parkdemo.R
import com.huluobo.a2208parkdemo.adapter.SignMonthAdapter
import com.huluobo.a2208parkdemo.databinding.ActivitySignMonthBinding
import com.huluobo.base.bean.SignMonthBean
import com.huluobo.base.mvvm.BaseActivity
import com.huluobo.base.net.Const
import dagger.hilt.android.AndroidEntryPoint
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody

@AndroidEntryPoint
class SignMonthActivity : BaseActivity<ActivitySignMonthBinding, SignViewModel>() {
    private lateinit var signMonthAdapter: SignMonthAdapter
    override fun initData() {
        val map = mutableMapOf<String, Int>()
        map[Const.PARAM_MONTH] = 1
        val json = Gson().toJson(map)
        val body = RequestBody.create(Const.MEDIA_TYPE.toMediaTypeOrNull(), json)
        vm.signMonth(body)

        vm.signMonthSuccess.observe(this) {
            val list = Gson().fromJson(it, SignMonthBean::class.java)
            signMonthAdapter.data.clear()
            signMonthAdapter.data.addAll(list)
            signMonthAdapter.notifyDataSetChanged()
        }
    }

    override fun initView() {
        binding.signMonthHeader.headerBack.setOnClickListener { finish() }
        binding.signMonthHeader.headerTitle.text = "月度考勤"

        binding.signMonthRv.layoutManager = LinearLayoutManager(this)
        signMonthAdapter = SignMonthAdapter()
        binding.signMonthRv.adapter = signMonthAdapter
    }
}